package syntaxtree;
import java.util.HashMap;
import java.util.Iterator;

import visitor.TranslateVisitor;
import visitor.Visitor;
import visitor.TypeVisitor;

/**
 * 
 * */
public abstract class Type {
	/***/
	public int beginLine, endLine, beginColumn, endColumn;
	/***/
	private int type;
	/***/
	private static int countType = 0;
	/***/
	private static HashMap<String, Integer> types = new HashMap<String, Integer>();

	/**
	 * 
	 * */	
	public Type(String type){
		this.type = Type.getType(type);
	}
		
	/**
	 * 
	 * */
	public boolean equals(Type t){
		return type == t.type;
	}
		
	/**
	 * 
	 * 
	 * */
	private static int getType(String name){
		if(types.containsKey(name)){
			return types.get(name);
		}
		else{
			types.put(name, countType);
			countType++;
			return countType - 1;
		}	
	}
		
	/**
	 * 
	 * 
	 * */	
	public String toString(){
		Iterator<String> it = types.keySet().iterator();
		while(it.hasNext()){
			String elem = it.next(); 
			if(types.get(elem) == type) return elem; 
		}
		return "Tipo nao conhecido";
	}
		
	/**
	 * 
	 * 
	 * */
	public abstract void accept(Visitor v);
	
	/**
	 * 
	 * 
	 * */
	public abstract Type accept(TypeVisitor v);
	
	/**
	 * 
	 * */
	public abstract translate.activationRegister.util.Exp accept(TranslateVisitor v);
}
